﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using ModelPredictPro.Predict.SVM;

namespace ModelPredictPro.WindowForms.UserControls {
    public partial class UCConsole : UserControl {
        public UCConsole() {
            InitializeComponent();
        }
        public ComponentFactory.Krypton.Toolkit.KryptonRichTextBox Consol {
            get { return txtConsole; }
        }

        public void Clear() {
            Consol.Clear();
        }

        public static string DEFAULT_OK_STRING = "OK";

        public void PublishInfo(SVMStepEventArgs e) {
            if (e.Info != "" && e.OccurringTime.HasValue)
                Consol.AppendText(string.Format("[{0}] {1}", e.OccurringTime.ToString(), e.Info));
            else {
                if (e.OccurringTime.HasValue)
                    Consol.AppendText(string.Format("{1} [{0}]", e.OccurringTime.ToString(), DEFAULT_OK_STRING));
                else
                    Consol.AppendText(e.Info);
                Consol.AppendText(Environment.NewLine);

            }
        }
        public void WriteLine(string info) {
            Consol.AppendText(string.Concat(info, Environment.NewLine));
        }
        public void InvokeWriteLine(string info) {
            Consol.Invoke(new Action<string>(WriteLine), info);
        }
        public void InvokePublishInfo(SVMStepEventArgs e) {
            Consol.Invoke(new Action<SVMStepEventArgs>(PublishInfo), e);
        }
        public string ConvertToString(TimeSpan span) {
            StringBuilder rst = new StringBuilder();
            bool index = false;
            if (span.Days != 0) {
                rst.AppendFormat("{0} days - ", span.Days);
                index = true;
            }
            if (index || span.Hours != 0) {
                rst.AppendFormat("{0} hours - ", span.Hours);
                index = true;
            }
            if (index || span.Minutes != 0) {
                rst.AppendFormat("{0} mins - ", span.Minutes);
                index = true;
            }
            if (index || span.Seconds != 0) {
                rst.AppendFormat("{0} secs - ", span.Seconds);
                index = true;
            }
            rst.AppendFormat("{0} msecs", span.Milliseconds);
            return rst.ToString();
        }
    }
}
